package com.example.xViewChat.Bean;

import io.ganguo.chat.core.protocol.Commands;
import io.ganguo.chat.core.protocol.Handlers;
import io.ganguo.chat.core.transport.Header;
import io.ganguo.chat.core.transport.IMRequest;
import io.ganguo.chat.core.transport.IMResponse;
import io.ganguo.chat.route.biz.bean.ClientType;
import io.ganguo.chat.route.biz.entity.User;
import io.ganguo.chat.route.server.dto.UserDTO;

import java.util.Random;

/**
 * Created by hasee on 2016-04-05.
 */
public class cmdBean extends BaseBean {

    public Header getmHeader() {
        return mHeader;
    }

    public void setmHeader(Header mHeader) {
        this.mHeader = mHeader;
    }

    Header mHeader;
    char set;
    String mString;


    public String getString() {
        return mString;
    }

    public void setString(String string) {
        this.mString = string;
    }


    public char getSet() {
        return set;
    }

    public void setSet(char set) {
        this.set = set;
    }


    public cmdBean() {
    }

    public cmdBean(IMRequest request) {
        mHeader = request.getHeader();

        set = 'q';
    }

    public cmdBean(IMResponse response) {
        mHeader = response.getHeader();

        set = 'p';
    }

    public IMRequest toRequest() {
        if (set == 'p')
            return null;
        IMRequest request = new IMRequest();
        request.setHeader(mHeader);

        return request;
    }

    public IMResponse toResponse() {
        if (set == 'q')
            return null;
        IMResponse reponse = new IMResponse();
        reponse.setHeader(mHeader);

        return reponse;
    }

    public static void main(String[] argc) {
        User user = new User();
        user.setClientType(ClientType.MAC.value());
        int x = new Random().nextInt(10000) + 3;
        System.out.println(4 + "登录");
        user.setAccount("test" + 4);
        user.setPassword("test" + 4);

        IMResponse resp = new IMResponse();
        Header header = new Header();
        header.setHandlerId(Handlers.USER);
        header.setCommandId(Commands.LOGIN_REQUEST);
        resp.setHeader(header);
        resp.writeEntity(new UserDTO(user));


        System.out.println(resp.toString());
        cmdBean cmd = new cmdBean(resp);
        System.out.println(cmd);

    }


}
